<?php
session_start();
	require_once "includes/config.php";
	require_once "includes/pagination.php";
    $itemPerPage=10;	
	
	$sg = $_REQUEST['sg2'];
	$key = $_REQUEST['key'];
	//$state = $_GET['state'];
	//$city = $_GET['city'];
	//$priceFrom = $_GET['priceFrom'];
	//$priceTo = $_GET['priceTo'];
	
	if(!empty($sg)) 
	{	
	
	 
		$sqlSelPro="SELECT *, tbl_wholeseller_product.product_name, tbl_users.user_id 
					FROM tbl_wholeseller_product, tbl_users 
					WHERE tbl_users.user_id=tbl_wholeseller_product.posted_by ";	
	
		$searchIncludes="";														
				
		  if($key!='')
		     $sqlSelPro.="  AND  tbl_wholeseller_product.product_name LIKE '%$key%' "; 
		    
		 
		/* else
		{
		$sqlSelPro="SELECT * FROM tbl_product";
		$pagelink="srch&sg";
	} */
  }
	$pLink = "srchwhole=1&sg2=$sg";	
	
	$pos     = strripos($sqlSelPro, "where");
	$curDate = date("Y-m-d G:i:s",time());
	//echo $curDate;
	
	//echo $sqlSelPro;
?>	
<div id='panel'>
<table>
	<tr>
		<td colspan="2" valign="top">	
		<div style="width: 950px; float: left; vertical-align: top; margin:15px 0px 5px 0px;">
			<a href="#" class="yellow_btn" style="float:right;">Regularly the higher the commission the more you earn per sale<br />
Regularly the lower the commission the more often you sell</a>
			<font class="grey_big" style="float:right; margin:7px 10px 0px 0px;">Pro Tips</font>
		</div>
			
		<div style="width: 950px; float: left; margin:10px 0px 5px 0px;">
		
		<div class="mypg_left_out">		
		<a href="#">
		<img src="images/arrow_back.png" style="border:none; margin:0px 5px 0px 0px;" />
		Back to Search Results
		</a>		
		</div>
		
		<div class="fullbox_out">	
			<strong class="orangehead">Choose Products to Sell</strong>
			<p style="margin: 5px 0px;" class="grey_txt">
				<i>Sell products for business or people and earn a commission. You choose the item with the best price and commission.</i>
			</p>	
	   	</div>
		
	   	</div>
		</td>
	</tr>
</table>

<table width="100%" border="0">

<tr>

<td>
<div style="width: 950px; float: left; vertical-align: top;">


<div class="mypg_left_out">
		<table style="width:100%">
		<?php
		 if($userType=='3' || $userType=='5')
		 {
		 ?>
		<tr>
			<td>
				<div class="fulldiv">
					<p style="color:#000000; font-size: 12px; font-weight: normal;">
					<?php echo $business_name ?><br />
					<?php echo $address_line_1 ?><br />
					</p>
				</div>
			</td>
		</tr>
		<?
		 }
		 ?>
		<tr>
        	<td width="214" valign="top">
			<p style="color:#767676; font-size: 14px; font-weight: normal; margin:5px 0px 5px 0px;">
				Refine Search
			</p>
			<div class="shourtbox">
			<table width="100%" border="0">
        <?php if($offerSettings)
		{
		?>
        <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td></td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_top.jpg); height:10px"></td>
              </tr>
              <tr>
                <td height="30" style=" background-image:url(images/LHS_gradient_bg.jpg); background-repeat:repeat-y;height:100px; vertical-align:top;"><div id="category-title">Offer from <?php echo $sellerName; ?> </div>
                    <br />
                  <div id="category-content"><?php echo $offer; ?></div>
                  </td>
              </tr>
              <tr>
                <td style=" background-image:url(images/LHS_menu_bottom.jpg); height:18px"></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <?php } ?>
          <tr>
            <td><table width="212"  border="0" cellpadding="0" cellspacing="0">
						  
              <tr>
                <td style="vertical-align:top;">
				<div id="category-title">Search Within Store</div>
                    <br />
                  <div class="fulldiv">
				  <center>
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
                        <input type="text" name="search_string" id="search_string" class="inputbg" style="width:120px; float:left;" />
                        <input type="submit" name="search" value="Search" class="yellow_btn" style="height:30px; margin:0px 0px 0px 10px;" />
                      </form>
                  </center>
				  </div>
				 </td>
              </tr>
			  
			  <tr>
                <td style="vertical-align:top;"><br />
				<div id="category-title">Category</div>
                    <br />
                  
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
						<select name="pro_subcategory" id="pro_subcategory" class="inputbg" onChange="getsubsearch(this.value);">
							<option value="" selected="selected">Select Category</option>
							<option value="" selected="selected">Category1</option>
							<option value="" selected="selected">Category2</option>
							<option value="" selected="selected">Category3</option>
						</select>
                    </form><br />
                 
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;"><br />
				<div id="category-title">Sub-Category</div>
                    <br />
                  
                    <form action="" method="post" name="formShopSearch" id="formShopSearch">
						<select name="pro_subcategory" id="pro_subcategory" class="inputbg" onChange="getsubsearch(this.value);">
							<option value="" selected="selected">Select Sub-Category..</option>
						<?php
						$sel="";
						$sql_shocat="SELECT * FROM tbl_category where parent_id='1'";
						$rst_shocat=mysql_query($sql_shocat);
						while($row_shocat=mysql_fetch_array($rst_shocat)) {
							 $cat_id=$row_shocat['category_id'];
							 $cat_name=$row_shocat['category_name'];
							 if(isset($_GET['subcatid']))
							 {
							  echo $_GET['subcatid'];
							 if($_GET['subcatid']==$cat_id)
							  echo $sel="selected='selected'";
							  else
							   $sel="";
							 }
							 
							 echo "<option value='$cat_id' ".$sel.">$cat_name</option>";
						}
						?>
						</select>
                    </form><br /> <br />
                 
				 </td>
              </tr>
			   
			  <tr>
                <td style="vertical-align:top;">
				<div id="category-title">By Price</div>
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=1">under - $10</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=2">$10 - $50</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=3">$50 - $100</a></p>  
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=4">$100 - $500</a></p> 
				<p><a href="seller_store.php?sid=<?php echo $_GET['sid'] ?>&pricebtw=5">$500 +</a></p>           
				 </td>
              </tr>
              
            </table></td>
          </tr>
        </table>
			</div>
			</td>
		</tr>
		
		<tr>
			<td>
				<div class="text_box2" style="text-align:center;">
				The more products you pick up the more sales you will have
				</div>
			</td>
		</tr>
		
		</table>
		</div>
		
		


<div class="fullbox_out">
<table width="100%" border="0">
  <tr>
    <td class="contentHeader"><h2>Search Results <?php if(!empty($searchFor)) echo " - ".$searchFor; ?></h2></td>
  </tr>
  <tr>
    <td>

		 <?php 		   
				   if(!empty($_GET['sortby'])) {
				   		if($_GET['sortby']=='lps') {
							$sqlSelPro .= " order by tbl_wholeseller_product.product_price ASC";		
						}
						else if($_GET['sortby']=='hps') {
							$sqlSelPro .= " order by tbl_wholeseller_product.product_price DESC";		
						}
						else if($_GET['sortby']=='bm') {
							$sqlSelPro .= " order by field(tbl_wholeseller_product.product_name, '$key') DESC";		
						}
						else if($_GET['sortby']=='gen') {
							$sqlSelPro .= " order by tbl_wholeseller_product.product_id ASC";		
						}
						
				   }		
				   $rstSelPro=mysql_query(getPagingQuery($sqlSelPro,$itemPerPage));			  
				   $num=mysql_num_rows($rstSelPro);				   
				   if($num==0)
					{					
					  	echo "No Products Found...";
					 
					}
				   else { ?>
				   		
					   <br><table width='90%' border='0' align='center' cellspacing='0'>
						       <tr>
							   	<td colspan='5'>&nbsp;									</td>
							   </tr>
							   <tr class='head-tr'>
								  <td height='26' width='68'>&nbsp;</td>
							      <td width='138'><strong>Product Code </strong></td>
							      <td width='138'> <strong>Product name </strong></td>
							     <td width='90'> <strong>--</strong> </td>
							     <td width='54'> <strong>Price</strong> </td>
				         </tr>
						<?php	
						
						 while($rowSelPro=mysql_fetch_array($rstSelPro))
					         {							   
						   $productId=$rowSelPro['product_id'];
						   $postedby=$rowSelPro['posted_by'];
						   $itemId=$rowSelPro['product_id'];
						   $productName=wordFormater($rowSelPro['product_name'],20);
						   $productTitle = $rowSelPro['product_name'];					   
						   $productPrice=$rowSelPro['product_price'];
						   $postedDate=$rowSelPro['posted_date'];
						    $productCode=$rowSelPro['product_code'];
						   
						   $pimage = getWholeProductImage($itemId,'p');
						   if($pimage['thumb']!="") {
						   		$productThumb = $pimage['thumb'];
						   } else {
						   		$productThumb="images/no_image.gif";	
						   }
						   ?>  
						   <tr>
						        <td height='106' valign="top">
						   			<div align='center'><img src='<?php echo $productThumb; ?>'></div>								 </td>								 
								 <td style='vertical-align:top; padding:10px;'><a href='index.php?wholeproducts=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>'> <?php echo $productCode; ?> </a> </td>
								 <td style='vertical-align:top; padding:10px;'> <a href='index.php?wholeproducts=<?php echo $itemId; ?>' title='<?php echo $productTitle; ?>'> <?php echo $productName; ?> </a> </td>
								 <td style='vertical-align:top; padding:10px;'><input type='image' src='images/buy.gif' style='cursor:pointer;' onClick=''></td>
								  <td style='vertical-align:top; padding:10px;'>$<?php echo number_format($productPrice,2); ?><br /><?php if($_SESSION['user_id_sess']) {?><A HREF="javascript:void(0)" onclick="window.open('sendowner.php?ownerid=<?php echo $postedby;?>&productid=<?php echo $productId;?>','welcome','width=500,height=300')">Message</A><?php } else {?><A HREF="index.php?signin">Message</A><?php }?></td>
						   </tr>	
							   <tr>
									 <td colspan='5'> <div style='border-top:1px solid #CCCCCC;'> </div> </td>
							   </tr>				 	
						 <?php } ?>				 
						</table>
	    <?php } ?>
	
	  <tr>
    		<td><div align="center"><?php
				   $link=$pLink;
				   echo $disp=getPagingLink($sqlSelPro,$itemPerPage,$link);							   
			 ?></div>
			</td>
  	  </tr>
 	</table>
	</td>
  </tr>
</table>
</div>